package com.lbj.googleplay.googleplay100.ui.holder;

import android.text.format.Formatter;
import android.view.View;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.lbj.googleplay.googleplay100.R;
import com.lbj.googleplay.googleplay100.domain.AppInfo;
import com.lbj.googleplay.googleplay100.http.HttpHelper;
import com.lbj.googleplay.googleplay100.utils.UIUtils;

import org.xutils.ImageManager;
import org.xutils.x;

/**
 *
 * 详情页-应用信息
 */

public class DetailAppinfoHolder extends BaseHolder<AppInfo> {


    private ImageView ivIcon;
    private TextView tvName;
    private RatingBar rbStar;
    private TextView tvDownloadNum;
    private TextView tvVersion;
    private TextView tvDate;
    private TextView tvSize;
    private ImageManager imageManager;

    @Override
    public View initView() {

        View view = UIUtils.inflate(R.layout.layout_detail_appinfo);
         ivIcon = view.findViewById(R.id.iv_icon);
         tvName = view.findViewById(R.id.tv_name);
         rbStar = view.findViewById(R.id.rb_star);
         tvDownloadNum = view.findViewById(R.id.tv_download_num);
         tvVersion= view.findViewById(R.id.tv_version);
         tvDate= view.findViewById(R.id.tv_date);
         tvSize= view.findViewById(R.id.tv_size);
         imageManager = x.image();
         return view;
    }

    @Override
    public void refreshView(AppInfo data) {
        imageManager.bind(ivIcon, HttpHelper.URL+"image?name="+data.iconUrl);
        tvName.setText(data.name);
        tvDownloadNum.setText("下载量:"+data.downloadNum);
        tvVersion.setText(data.version);
        tvDate.setText(data.date);
        tvSize.setText(Formatter.formatFileSize(UIUtils.getContext(),data.size));
        rbStar.setRating(data.stars);
    }
}
